package cn.keniykey.mc.viewlibrary.view.api.template;

import javax.annotation.Nullable;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

import cn.keniykey.mc.viewlibrary.view.api.AbFrameView;
import cn.keniykey.mc.viewlibrary.view.api.FrameViewBundle;
import cn.keniykey.mc.viewlibrary.view.api.FrameViewIntent;

public final class InputViewIntentBuilder {
	static enum  EInputMenuViewCustomDisplay{
		FULLY,MATERIAL;
	}
	static enum EInputMenuViewIntentKey{
		CUSTOMDISPLAY,CUSTOMDISPLAY_CONFIRM,CUSTOMDISPLAY_INPUT,CUSTOMDISPLAY_COUNTDOWN,
		COUNTDOWN,CUSTOM_TITLE,CUSTOM_INPUT_NAME,CUSTOM_INPUT_LORE,
		FORWARD_CONTENT;
	}
	
	private FrameViewIntent intent;
	private FrameViewBundle bundle;
	
	public InputViewIntentBuilder(Class<? extends AbFrameView> clazz_targetview1) {
		this.intent = new FrameViewIntent(clazz_targetview1);
	}
	
	public FrameViewIntent build() {
		if(this.intent == null) throw new RuntimeException("Already built and returned Intent, recreate it(已经构建过并返回Intent，请重新创建)");
		try {
			return this.intent;
		}finally {
			this.intent = null;
			this.bundle = null;
		}
	}
	private void putValue(EInputMenuViewIntentKey key,@Nullable Object value) {
		if(null == this.bundle) this.intent.putExtras((this.bundle = new FrameViewBundle()));
		this.bundle.putValue(key.toString(), value);
	}
	public void useFullyCustomDisplay() {
		this.putValue(EInputMenuViewIntentKey.CUSTOMDISPLAY, EInputMenuViewCustomDisplay.FULLY);
	}
	public void setFullyCustomDisplayOfConfirm(ItemStack item) {
		this.putValue(EInputMenuViewIntentKey.CUSTOMDISPLAY_CONFIRM, item);
	}
	public void setFullyCustomDisplayOfInput(ItemStack item) {
		this.putValue(EInputMenuViewIntentKey.CUSTOMDISPLAY_INPUT, item);
	}
	public void setFullyCustomDisplayOfCountdown(ItemStack item) {
		this.putValue(EInputMenuViewIntentKey.CUSTOMDISPLAY_COUNTDOWN, item);
	}
	
	public void useMaterialCustomDisplay() {
		this.putValue(EInputMenuViewIntentKey.CUSTOMDISPLAY, EInputMenuViewCustomDisplay.FULLY);
	}
	public void setMaterialCustomDisplayOfConfirm(Material type) {
		this.putValue(EInputMenuViewIntentKey.CUSTOMDISPLAY_CONFIRM, type);
	}
	public void setMaterialCustomDisplayOfInput(Material type) {
		this.putValue(EInputMenuViewIntentKey.CUSTOMDISPLAY_INPUT, type);
	}
	public void setMaterialCustomDisplayOfCountdown(Material type) {
		this.putValue(EInputMenuViewIntentKey.CUSTOMDISPLAY_COUNTDOWN, type);
	}
	
	public void setInputCountdown(int second) {
		if(second > 127) throw new RuntimeException("The original required a limit of 127(原版要求，上限为127。)");
		this.putValue(EInputMenuViewIntentKey.COUNTDOWN, Math.max(0, second));
	}
	public void setCustomTitle(String title) {
		this.putValue(EInputMenuViewIntentKey.CUSTOM_TITLE, title);
	}
	public void setForwardContent(Object obj) {
		this.putValue(EInputMenuViewIntentKey.FORWARD_CONTENT, obj);
	}
}